package com.dong.rabbitmq.deadqueue;

import com.dong.rabbitmq.utils.RabbitMqUtil;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;

/**
 * @author dongjian
 * 死信队列生产者
 */
public class DeadQueueProducer {

    /**
     * 普通交换机
     */
    public static final String NORMAL_EXCHANGE = "normal_exchange";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtil.getChannel();
        // properties参数对象设置消息过期时间 单位 ms 10000=10s
        // 1.消息ttl过期
        AMQP.BasicProperties properties = new AMQP.BasicProperties()
                .builder()
                .expiration("10000")
                .build();
        // 生产消息 10条
        for (int i = 1; i < 11; i++) {
            String msg = "info-" + i;
            channel.basicPublish(NORMAL_EXCHANGE, "zhangsan", null, msg.getBytes("UTF-8"));
        }
    }
}
